package com.wuyi.tea.controller.common;


import com.wuyi.tea.domain.dto.AuthorizationDTO;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "认证模块")
@RestController
public class AuthorizationController {

    @Resource
    private UserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public R login(@RequestBody AuthorizationDTO authorizationDTO){

        log.info("{}登录中...",authorizationDTO);
        String jwt= userService.login(authorizationDTO);
        return R.success("登录成功",jwt);
    }

    @ApiOperation("退出登录")
    @GetMapping("/logout")
    public R logout(){
        // TODO

        return R.success();
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public R register(@RequestBody AuthorizationDTO authorizationDTO){
        log.info("有用户注册中，注册信息：\n{}",authorizationDTO);
        userService.register(authorizationDTO);
        return R.success("注册成功",null);
    }

}
